<template>
	<view class="success-wrapper" :style="{paddingTop: paddingTop + 'px'}">
		<navBar :title="title" :customBack="true" @back="back" marginLeft="40%" />
		<view class="success-content" :style="{height: 'calc(100vh - '+paddingTop+ 'px)'}">
			<view class="img">
				<image
					src="https://coach-vehicle-uat-1313990257.cos.ap-beijing.myqcloud.com/miniapp/guarantee/success.png">
				</image>
			</view>
			<view class="title" v-if="!type">服务项确认成功</view>
			<view class="title" v-if="type">{{ content }}</view>
			<view class="dec" v-else>{{ content }}</view>
		</view>
		<view class="footer">
			<view class="btn" v-if="type">
				<u-button type="primary" text="查看记录" @click="lookOrder" :plain="true"></u-button>
				<u-button type="primary" text="回到首页" @click="backHome"></u-button>
			</view>
			<view class="btn" v-else>
				<u-button type="primary" text="回到首页" @click="backHome"></u-button>
				<u-button type="primary" text="完成" @click="lookOrder"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import navBar from '@/components/navBar.vue'
	import {
		mapGetters
	} from 'vuex'

	export default {
		components: {
			navBar
		},
		data() {
			return {
				paddingTop: '',
				title: '申请轮胎售后',
				content: '售后质保申请提交成功',
				orderId: '',
				type: true,
				resubmit: 0, //判断是否是重新提交的数据
			}
		},
		methods: {
			backHome() {
				uni.switchTab({
					url: '/pages/index/index/index'
				})
			},
			back() {
				if (this.type) {
					if (this.resubmit != '0') {
						uni.navigateTo({
							url: `/indexPack/guarantee/detail?id=${this.resubmit}&resubmit=1`
						});
					} else {
						uni.reLaunch({
							url: `/indexPack/guarantee/index?id=4&toHome=1`
						});
					}
				} else {
					uni.navigateTo({
						url: `/indexPack/guarantee/index?id=4&toHome=1`
					});
				}


			},
			lookOrder() {
				if (this.orderId) {
					uni.navigateTo({
						url: `/indexPack/guarantee/applyDetail?id=${this.orderId}&success=1`
					});
				} else {
					uni.reLaunch({
						url: `/indexPack/guarantee/index?id=4`
					});
				}

			}
		},
		onLoad(option) {
			this.paddingTop = this.$store.getters['global/getSystemInfo'].navBarHeight
			this.type = true
			if (option.type == 'applyDetail') {
				this.title = '确认服务成功'
				this.content = '非常感谢您的确认和评价'
				this.type = false
			}
			if (option.id) {
				this.orderId = option.id
			}
			this.resubmit = 0
			if (option.resubmit) {
				this.resubmit = option.resubmit
			}
			// uni.showLoading({
			// 	title: '加载中...'
			// })
			// const eventChannel = this.getOpenerEventChannel()
			// eventChannel.on('formInfo', this.initForm)
		}
	}
</script>

<style lang="scss" scoped>
	.success-wrapper {
		position: relative;
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;

		.success-content {
			height: 100vh;

			.img {
				padding-top: 290rpx;
				display: flex;
				justify-content: center;
				padding-bottom: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
				}
			}

			.title {
				width: 100%;
				text-align: center;
			}

			.dec {
				width: 100%;
				margin-top: 20rpx;
				color: rgba(0, 0, 0, 0.5);
				text-align: center;
			}


		}

		.footer {
			background: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			padding: 30rpx 32rpx;
			z-index: 3;

			.btn {
				display: flex;

				/deep/ .u-button {
					margin: 0 20rpx;
				}
			}
		}
	}
</style>